package edu.uoc.tdp.pac4.server.connexiomantenimnet.i18n;

import java.util.Locale;
import java.util.MissingResourceException; 
import java.util.ResourceBundle;

public class ServerLanguageUtils {
	private static ResourceBundle resourceBundle; 
	private static String currentBaseName; 
	private static Locale currentLocale;
	public static synchronized boolean setDefaultLanguage(String baseName) { 
		try {
			currentBaseName=baseName;
			Locale locale = Locale.getDefault();
			resourceBundle = ResourceBundle.getBundle(baseName,locale); 
			return true;
		} catch (MissingResourceException e) { 
			e.printStackTrace();
	        return false;
	    } 
	}
	public static synchronized boolean setLanguage(String baseName, Locale locale) { 
		try {
			currentBaseName=baseName;
			currentLocale=locale;
			resourceBundle = ResourceBundle.getBundle(baseName,locale); 
			return true;
		} catch (MissingResourceException e) { 
			e.printStackTrace();
			return false;
		}
	}

	public static String getMessage(String key) { 
		try {
			return resourceBundle.getString(key); 
		} catch(MissingResourceException e) {
			return new String();
		} 
	}
	public static String getCurrentBaseName() { return currentBaseName; }
	public static Locale getCurrentLocale() { return currentLocale; }	
}

